package com.wlyuan.open.scanner.controller;

import com.wlyuan.open.dto.OpenSearchSourceDataDTO;
import com.wlyuan.open.dto.incr.IncrSourceDTO;
import com.wlyuan.open.dto.incr.IncrTenantDTO;
import com.wlyuan.open.dto.incr.IncrTenantNameDTO;
import com.wlyuan.open.scanner.service.ScannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author lijing
 * @description
 */
@Api(tags = "增量扫描")
@Validated
@RequestMapping("/scanner/incr")
@RestController
@Slf4j
public class ScannerIncrController {
    @Autowired
    private ScannerService scannerService;

    @ApiOperation("增量扫描")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sourceId", value = "sourceId:业务id", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "类型：公司租户,个体司机租户,用户,司机,车辆,客户,线下承运方,线上承运方,物品,收货方,合约,订单,运单,拼车单,合约,报价,对账单,收付款,脱普扩展,运单关系,合单报价", paramType = "query", allowMultiple = true)
    })
    @PostMapping("/")
    public void incr(@RequestBody IncrSourceDTO source) {
        logger.info("************************************************************");
        scannerService.increment(source);
    }

    @ApiOperation("多租户增量扫描")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tenantId", value = "tenantId:租户id", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "类型：公司租户,个体司机租户,用户,司机,车辆,客户,线下承运方,线上承运方,物品,收货方,合约,订单,运单,拼车单,合约,报价,对账单,收付款,运单关系,合单报价", paramType = "query", allowMultiple = true)
    })
    @PostMapping("/tenant")
    public void incrTenant(@RequestBody IncrTenantDTO source) {
        logger.info("************************************************************");
        scannerService.incrByTenant(source);
    }

    @ApiOperation("多业务多租户增量扫描")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tenantId", value = "tenantId:租户id", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "类型：公司租户,个体司机租户,用户,司机,车辆,客户,线下承运方,线上承运方,物品,收货方,合约,订单,运单,拼车单,合约,报价,对账单,收付款,合单报价", paramType = "query", allowMultiple = true)
    })
    @PostMapping("/name")
    public void incrNames(@RequestBody IncrTenantNameDTO source) {
        logger.info("************************************************************");
        scannerService.incrByTenantName(source);
    }

    @ApiOperation("同步失败")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sourceClass", value = "类型：1:客户,3:收货方,4:物品,5,订单,6:运单,8:用户,10:司机,11:车辆,12:合同,13:对账单,14:租户邀请关系,15:合约,16:报价,17:收付款,18:top定制,19:拼车单,20:运单关系,21:合单报价", paramType = "query"),
            @ApiImplicitParam(name = "tenantId", value = "tenantId:租户id", paramType = "query", required = false),
            @ApiImplicitParam(name = "createAt", value = "开始时间", paramType = "query", required = false),
    })
    @PostMapping("/fail")
    public void incrFail(@RequestBody OpenSearchSourceDataDTO source) {
        logger.info("************************************************************");
        scannerService.incrFail(source);
    }

    @ApiOperation("根据创建时间区间同步")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "类型：租户,用户,司机,车辆,客户,线下承运方,线上承运方,物品,收货方,合约,订单,运单,运单关系,拼车单,报价,合单报价,对账单,收付款,脱普扩展,合同", paramType = "query", allowMultiple = true)
    })
    @PostMapping("/time")
    public void time(@RequestParam(value = "tenantId", required = false) Long tenantId, @RequestParam("name") String name, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) {
        scannerService.time(tenantId, name, startTime, endTime);
    }
}
